<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

include "/library/receipt.php";
if(isset($_GET['addproduct'])){
    viewOneProduct($_GET['addproduct'],$_GET['Typeid']);
    exit();
}
if(isset($_GET['add'])){
    addreceipt($_GET);
    //header('location: receipt.php');
}else if(isset($_GET['edit'])){
    editReceipt($_GET);
    //header('location: receipt.php');
}else if(isset($_GET['search'])){
    search($_GET['search']);
    exit();
}else if(isset($_GET['editform'])&&isset($_GET['id'])){
    $printR = query_one($_GET['id']);
    $printP = query_one_product($_GET['id']);
}else if(isset($_GET['delete'])){
    deleteReceipt($_GET['id']);
    header('location: receipt.php');
}
include "header.php";
?>
<link type="text/css" href="css/smoothness/jquery-ui-1.8.10.custom.css" rel="stylesheet" />	
<script type="text/javascript" src="js/jquery.ui.core.js"></script>
<script type="text/javascript" src="js/jquery.ui.datepicker.js"></script>
<script type="text/javascript" src="js/jquery-ui-timepicker-addon.js"></script>
<script type="text/javascript" src="js/recent_add.js"></script>


<div id="product" align="center" width="100%">
    <form id="formSend" action="receipt_add.php" method="get" >
<table  id="tableLine">
    <?php  if(isset($_GET['editform'])){ ?>
        <tr>
            <th>เลขที่ใบเสร็จ</th>
            <td id="otherdetail" colspan="5"><?php if(isset($_GET['editform'])) echo receipt_id_check ($printR['id']); ?><input type="hidden" name="id" value="<?php if(isset($_GET['editform'])) echo receipt_id_check ($printR['id']); ?>"></td>
        </tr>
    <?php } ?>
        <tr>
            <th >ประเภทใบเสร็จ</th>
            <td id="otherdetail" colspan="5">
                <input type="radio" name="receipt_type" value="0" <?php if(isset($_GET['editform']))if ($printR['receipt_type']==0)echo "checked=checked"?>>ใบส่งของ
                <br>
                <input type="radio" name="receipt_type" value="1" <?php if(isset($_GET['editform']))if ($printR['receipt_type']==1)echo "checked=checked"?>>ใบเสร็จชั่วคราว
            </td>
        </tr>
        <tr>
            <th>ชื่อลูกค้า</th>
            <td id="otherdetail"colspan="5" ><input type="text" name="customer_name" value="<?php if(isset($_GET['editform'])) echo $printR['customer_name']; ?>"></td>
        </tr>
        <tr>
            <th >วันที่</th>
            <td id="otherdetail" colspan="5"><?php if(isset($_GET['editform'])) echo $printR['dateString']; else date_thai(); ?>
            <input type="hidden" name="dateString" value="<?php if(isset($_GET['editform'])) echo $printR['dateString']; else date_thai(); ?>">
            <input type="hidden" name="date" value="<?php if(isset($_GET['editform'])) echo sql_to_date($printR['date']); else date_int(); ?>">
            </td>
        </tr>
        <tr>
            <th id="full" colspan="6">สินค้า</th>
            
        </tr>
        
        <tr>
            <td colspan="6">ค้นหา <input type="text" id="search"  name="search" value="" size="68"  ></td>
        </tr>
 </table>
 <table  id="searchItem">

        <tr>
            <tbody id="searchbox" colspan="2"></tbody>
        <tr>
        <tbody id="tagresult">
        <tr >
            <th colspan="6">เลือกสินค้า</th>
        </tr>
       </tbody>
</table>
        <?php if(isset($_GET['editform'])){
            while($transaction = mysql_fetch_array($printP)){
            ?>
            <script type="text/javascript">
                addProduct('<?=$transaction['product_id']; ?>','<?=$transaction['product_type_id']; ?>','<?=$transaction['amount']; ?>',<?=$transaction['transaction_type']; ?>);

            </script>

       <? }

       } ?>
<table id="insertItem">

                    <tr>
                        <th>รหัสสินค้า</th>
                        <th >ชื่อสินค้า</th>
                        <th>ประเภทการขาย</th>
                        <th>คงเหลือ</th>
                        <th>หน่วย</th>
                        <th>ราคาทุน</th>
                        <th>ราคาขายต่อหน่วย</th>
                        <th >จำนวน</th>
                        <th >หมายเหตุ</th>
                        <?php if(!isset($_GET['editform'])){ ?>
                        <th></th>
                            <?php } ?>
                    </tr>


                    <tbody id="searchresult">
                        <div  id="product_id"></div>
                    </tbody>
                    <tbody id="countresult">

                    </tbody>
</table>
            
     <div name="addCustomer_type">
        <?php
            if(isset($_GET['editform'])){ ?>

        <input type="submit" name="edit" value=" แก้ไข ">

           <?php }else { ?>


        <input type="submit" id="subok" name="add" value=" เพิ่ม ">
        <?php } ?>
</div>
    </form>

    <p>
    </p>

</div>
